﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Abp.Application.Services;
using Abp.AutoMapper;
using Abp.Web.Models;
using KelonProud.Administration.Dtos;
using KelonProud.Administration.Managers.Configuration;

namespace KelonProud.Administration.Services
{
    public interface ICommonAppService //:IApplicationService
    {
        Task<IList<IconGroupDto>> GetIconsByName(string name);
    }

    public class CommonAppService : ICommonAppService
    {
        private readonly IconManager _iconManager;

        public CommonAppService(IconManager iconManager)
        {
            _iconManager = iconManager;
        }

        [WrapResult(WrapOnSuccess = false)]
        public async Task<IList<IconGroupDto>> GetIconsByName(string name)
        {
            var icons = await _iconManager.GetIconsByNameAsync(name);
            var iconList = icons.Select(s => s.MapTo<IconDto>());

            var result = iconList.GroupBy(g => g.Type)
                .Select(s => new IconGroupDto()
                {
                    Type = s.Key,
                    IconsList = s.ToList()
                }).ToList();

            return result;
        }
    }
}
